import md5 from 'js-md5';
import { httpUrl, ERR_OK, ERR_CUSTOM } from 'api/config';
import { changeDataType } from 'common/js/util'; 

export function goLogin(obj) {
	let url = `${httpUrl}/login`;
	
	let data = {
		userName: obj.username,
		password: md5(obj.password)
	};
	
	return axios.post(url, changeDataType(data), {
		withCredentials: true
	})
		.then((res) => {
			return Promise.resolve(res.data)
		})
		.catch((err) => {
			return Promise.reject({
				code: ERR_CUSTOM,
				message: '请检查网络是否畅通，或'
			})
		})
}
